<template>
  <ContainerLayoutV2 ref="containerLayoutRef" class="training-statistics">
    <template #form>
      <h1>TestCGT</h1>
      <!-- <el-button @click="handleClickBtnLogin">登录</el-button>
      <el-button @click="handleClickBtnGetAssetLib">获取资产库</el-button>
      <el-button @click="handleClickBtnGetAssetTreeFolder">获取资产库数据</el-button> -->
    </template>
  </ContainerLayoutV2>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import ContainerLayoutV2 from '../layout/ContainerLayoutV2.vue'
import axios from 'axios'

const userInfo = ref<any>({})
const distinctDB = ref<any>()

const http = async (data: any = {}) => {
  const res = await axios({
    method: 'POST',
    url: 'http://192.168.19.5/api.php',
    data,
  })
  return res.data.data
}

const setUserInfo = async () => {
  const form = new FormData()
  form.append('data[controller]', 'account')
  form.append('data[method]', 'login')
  form.append('data[app]', 'api')
  // form.append('data[account]', 'zhanghailong')
  // form.append('data[password]', 'Zhhl071005')
  form.append('data[account]', 'sangyang')
  form.append('data[password]', '1qaz2wsx3edc4rfv')
  const res = await http(form)
  console.log('登录', res)
  userInfo.value = res
}

const getProjectDistinct = async () => {
  const form = new FormData()
  form.append('data[token]', userInfo.value.token)
  form.append('data[controller]', 'project')
  form.append('data[method]', 'distinct')
  form.append('data[app]', 'api')
  form.append('data[distinct_sign]', 'project.database')
  form.append('data[sign_filter_array][0][]', 'project.database')
  form.append('data[sign_filter_array][0][]', '=')
  form.append('data[sign_filter_array][0][]', 'proj_freja')
  const res = await http(form)
  distinctDB.value = res[0]
  console.log('项目数据库列表', res)
}

const getTastModules = async () => {
  const form = new FormData()
  form.append('data[token]', userInfo.value.token)
  form.append('data[controller]', 'task')
  form.append('data[method]', 'modules')
  form.append('data[app]', 'api')
  form.append('data[db]', distinctDB.value)
  const res = await http(form)
  console.log(`获取 ${distinctDB.value} 所有启用任务的模块`, res)
}
const getFilterByTast = async () => {
  const form = new FormData()
  form.append('data[token]', userInfo.value.token)
  form.append('data[controller]', 'task')
  form.append('data[method]', 'get_filter')
  form.append('data[app]', 'api')
  form.append('data[db]', distinctDB.value)
  form.append('data[module]', 'asset')
  form.append('data[order_sign_array][]', 'asset.entity')
  form.append('data[order_sign_array][]', 'task.pipeline_sort_id')
  form.append('data[limit]', '100')
  form.append('data[start_num]', '0')
  form.append('data[sign_array][]', 'asset.id')
  form.append('data[sign_array][]', 'asset.entity')
  form.append('data[sign_array][]', 'asset.cn_name')
  form.append('data[sign_array][]', 'task.pipeline_sort_id')
  form.append('data[sign_array][]', 'pipeline.entity')
  form.append('data[sign_array][]', 'task.status')
  form.append('data[sign_array][]', 'task.artist')
  form.append('data[sign_array][]', 'task.create_time')
  form.append('data[sign_array][]', 'task.flow_name')
  form.append('data[sign_array][]', 'task.file_status')
  form.append('data[sign_array][]', 'task.review_show_data')
  form.append('data[sign_array][]', 'task.flow_id')
  form.append('data[sign_array][]', 'task.pipeline_notice_from_wait')
  //
  form.append('data[sign_filter_array][0][]', 'task.artist')
  form.append('data[sign_filter_array][0][]', 'has')
  form.append('data[sign_filter_array][0][]', '张成龙')
  const res = await http(form)
  console.log(`获取 ${distinctDB.value} asset 【Tast】记录列表`, res)
}
const getFilterByTastByShot = async () => {
  const form = new FormData()
  form.append('data[token]', userInfo.value.token)
  form.append('data[controller]', 'task')
  form.append('data[method]', 'get_filter')
  form.append('data[app]', 'api')
  form.append('data[db]', distinctDB.value)
  form.append('data[module]', 'shot')
  form.append('data[order_sign_array][]', 'seq.entity')
  form.append('data[order_sign_array][]', 'shot.entity')
  // form.append('data[limit]', '100')
  // form.append('data[start_num]', '0')
  form.append('data[sign_array][]', 'shot.id')
  form.append('data[sign_array][]', 'shot.entity')
  form.append('data[sign_array][]', 'shot.artist')
  form.append('data[sign_array][]', 'shot.last_update_by')
  form.append('data[sign_array][]', 'seq.id')
  form.append('data[sign_array][]', 'seq.entity')
  form.append('data[sign_array][]', 'seq.artist')
  form.append('data[sign_array][]', 'task.pipeline_sort_id')
  form.append('data[sign_array][]', 'task.namex')
  form.append('data[sign_array][]', 'task.entity')
  form.append('data[sign_array][]', 'task.status')
  form.append('data[sign_array][]', 'task.artist')
  form.append('data[sign_array][]', 'task.create_time')
  form.append('data[sign_array][]', 'task.flow_name')
  form.append('data[sign_array][]', 'task.file_status')
  form.append('data[sign_array][]', 'task.review_show_data')
  form.append('data[sign_array][]', 'task.flow_id')
  form.append('data[sign_array][]', 'task.pipeline_notice_from_wait')
  //

  form.append('data[sign_filter_array][0][]', 'task.artist')
  form.append('data[sign_filter_array][0][]', 'has')
  form.append('data[sign_filter_array][0][]', '张成龙')

  const res = await http(form)
  console.log(`获取 ${distinctDB.value} shot 【Tast】记录列表`, res)
}
const getFieldsAndStrByTast = async () => {
  const form = new FormData()
  form.append('data[token]', userInfo.value.token)
  form.append('data[db]', distinctDB.value)
  // form.append('data[controller]', 'flow')
  // form.append('data[method]', 'get_node')
  // form.append('data[app]', 'api')
  // form.append('data[flow_id]', 'AEDB1A91-FF1F-B235-2E82-5448C7ED3839')

  form.append('data[controller]', 'task')
  form.append('data[method]', 'fields_and_str')
  form.append('data[app]', 'api')
  form.append('data[module]', 'shot')

  const res = await http(form)
  console.log(`获取 ${distinctDB.value} shot 获取所有字段标识和中文名`, JSON.stringify(res))
}

const getStatusAndColor = async () => {
  const form = new FormData()
  // form.append('data[token]', userInfo.value.token)
  // form.append('data[db]', distinctDB.value)
  // form.append('data[controller]', 'status')
  // form.append('data[method]', 'get_status_and_color')
  // form.append('data[app]', 'api')

  // const res = await http(form)
  // console.log(`获取所有状态的名称和颜色`, res)

  // project.database: "proj_freja"
  //  [ "(",["act","has","3"], "or", ["act","has","4"],")", "and", ["shot",">","6"], "and", ["shot","in",["6"]]) ];
  form.append('data[token]', userInfo.value.token)
  form.append('data[controller]', 'project')
  form.append('data[method]', 'get_filter')
  form.append('data[app]', 'api')
  // form.append('data[sign_filter_array]', JSON.stringify('["project.database","=","proj_freja"]'))
  // form.append('data[sign_filter_array][0][]', '["project.database","=","proj_freja"]')
  // form.append('data[sign_filter_array][0][]', '["project.database","=","proj_freja"]')
  // form.append('data[sign_filter_array][0][]', '["project.database","=","proj_freja"]')
  form.append('data[sign_filter_array][0][]', 'project.database')
  form.append('data[sign_filter_array][0][]', '=')
  form.append('data[sign_filter_array][0][]', 'proj_freja')
  form.append('data[sign_array][0]', 'project.full_name')
  form.append('data[sign_array][1]', 'project.database')
  form.append('data[sign_array][2]', 'project.status')
  form.append('data[order_sign_list]', 'project.entity')

  const res = await http(form)
  // const config = {
  //   token: userInfo.value.token,
  //   db: distinctDB.value,
  //   controller: 'project',
  //   method: 'get_filter',
  //   app: 'api',
  //   sign_filter_array: ['project.database', '=', 'proj_freja'],
  //   order_sign_list: 'project.entity',
  // }

  // const res = await http(JSON.stringify(config))
  console.log(`get_filter 获取记录列表`, res)
}

const getCount = async () => {
  const form = new FormData()
  form.append('data[token]', userInfo.value.token)
  form.append('data[db]', distinctDB.value)
  form.append('data[controller]', 'task')
  form.append('data[method]', 'count')
  form.append('data[app]', 'api')
  form.append('data[module]', 'asset')
  // form.append('data[module]', 'shot')

  // form.append('data[sign_filter_array][0][]', 'task.status')
  // form.append('data[sign_filter_array][0][]', '=')
  // form.append('data[sign_filter_array][0][]', 'Approve')

  const res = await http(form)
  console.log(`getCount：`, res)
}

const hasDatabase = async () => {
  const form = new FormData()
  form.append('data[token]', userInfo.value.token)
  form.append('data[controller]', 'project')
  form.append('data[method]', 'count')
  form.append('data[app]', 'api')
  form.append('data[sign_filter_array][0][]', 'project.database')
  form.append('data[sign_filter_array][0][]', '=')
  form.append('data[sign_filter_array][0][]', 'proj_freja')
  const res = await http(form)
  console.log(`hasDb`, JSON.stringify(res))
}

onMounted(async () => {
  await setUserInfo()
  await getProjectDistinct()
  await getTastModules()
  await getFilterByTast()
  await getStatusAndColor()
  await getFieldsAndStrByTast()
  await getFilterByTastByShot()
  await hasDatabase()
  await getCount()
})
</script>
